package de.fhaugsburg.games.boardgames.scrabble.wordlist;

import java.io.InputStream;
import java.util.List;
import java.util.Scanner;

import de.fhaugsburg.util.Trie;

//import sun.text.Trie;

public class WordTrieList implements IWordList {

	//import sun.text.Trie;
	private Trie wordList;
	
	
	public WordTrieList() {
		wordList = new Trie();
		
		try {	
//			File list = new File (System.getProperty("user.dir")  + "/resource/wordlists/wordlist_big.txt");
			InputStream list = this.getClass().getResourceAsStream("/resource/wordlists/wordlist_small.txt");
			Scanner scanner = new Scanner(list).useDelimiter("[^A-Za-zÄäÜüÖö]+");
//			Scanner scanner = new Scanner(list).useDelimiter("[^A-Za-z]+"); 
			int i = 0;
			while(scanner.hasNext()) {
				i++;
				wordList.add(scanner.next().toLowerCase());
			}
			scanner.close();
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
	
	
	public boolean contains(List<String> words) {
		if (words.isEmpty()) return false;
		for (String word : words){
			if(!wordList.containsWord(word)) return false;
		}
		return true;
	}

	public boolean containsPrefix(String prefix) {
//		System.out.println("prefix: " + prefix + " -> words: " + wordList.getWords(prefix));
		//if (wordList.getWords(prefix.toLowerCase()).size() > 0) return true;
		//return false;
		return wordList.containsPrefix(prefix);
	}

	public boolean containsPrefix(List<String> prefix) {
//		System.out.println("prefixes: " + prefix);
		if (prefix.size() == 0) return false;
		for (String string : prefix) {
			if (!containsPrefix(string)) return false;
		}
		return true;
	}

	public List<String> getList() {
		return wordList.getWords("");
	}

}
